package cn.bupt.data
{
	import flash.events.Event;
	import flash.utils.ByteArray;

	public class DataSource extends Event{
		public var frequency:Number = 1;
		public var amplitude:Number = 1;
		public var data:ByteArray = new ByteArray;
		public static const SOURCE:String = 'SOURCE';
		
		public function DataSource(type:String){
			for(var i:int=0;i<240;i++){
				data[i]=127;
			}
			super(type);
		}
		public function setType(newType:String):DataSource{
			var ds:DataSource = new DataSource(newType);
			if(this.data == null)
				return ds;
			ds.amplitude = this.amplitude;
			ds.frequency = this.frequency;
			for(var i:int;i<data.length;i++){
				ds.data[i] = data[i];
			}
			return ds;
		}
		public function getData():ByteArray{
			var temp:ByteArray = new ByteArray;
			for(var i:int=0;i<240;i++){
				temp[i] = this.data[i];
			}
			return temp;
		}
/*		public function set frequency(_frequency:Number):void{
			this.frequency_ = _frequency;
		}
		public function set amplitude(_amplitude:int):void{
			this.amplitude_ = _amplitude;
		}
		public function set data(_data:ByteArray):void{
			this.data_ = _data;
		}
		public function get frequency():Number{
			return this.frequency_;
		}
		public function get amplitude():int{
			return this.amplitude_;
		}
		public function get data():ByteArray{
			return this.data_;
		}*/
		
		override public function clone():Event{
			var ds:DataSource = new DataSource(type);
			if(this.data == null)
				return ds;
			ds.amplitude = this.amplitude;
			ds.frequency = this.frequency;
			for(var i:int;i<data.length;i++){
				ds.data[i] = data[i];
			}
			return ds;
		}
		override public function toString():String{
			return formatToString("DataSource");
		}
		/*		public override clone():DataSource{
		var ds:DataSource = new DataSource;
		if(this.data == null)
		return ds;
		ds.amplitude = this.amplitude;
		ds.frequency = this.frequency;
		for(var i:int;i<data.length;i++){
		ds.data[i] = data[i];
		}
		return ds;
		}*/
		/*		public function DataSource(_frequency:Number,_amplitude:Number,_data:ByteArray){
		this.frequency_ = _frequency;
		this.amplitude_ = _amplitude;
		this.data_ = _data;
		}*/
		//赋值方法，为了防止以后出现空指针地址异常
	}
}